﻿USE [Portal]
GO
/****** Object:  Table [dbo].[AppUser]    Script Date: 2/6/2014 2:54:04 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AppUser](
	[AppUserID] [bigint] IDENTITY(1,1) NOT NULL,
	[GlobalID] [nvarchar](50) NULL,
	[UserName] [nvarchar](50) NULL,
	[ProviderID] [nvarchar](50) NULL,
	[DateCreated] [date] NULL,
	[Email] [nvarchar](150) NULL,
	[InWorkflow] [int] NULL,
	[Salt] [nvarchar](50) NULL,
	[Secret] [nvarchar](250) NULL,
 CONSTRAINT [PK_AppUser] PRIMARY KEY CLUSTERED 
(
	[AppUserID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Forum]    Script Date: 2/6/2014 2:54:05 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Forum](
	[Forum] [varchar](50) NULL,
	[ForumID] [bigint] NOT NULL,
	[Template] [xml] NULL,
	[FileID] [bigint] NULL,
 CONSTRAINT [PK_Forum] PRIMARY KEY CLUSTERED 
(
	[ForumID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Post]    Script Date: 2/6/2014 2:54:05 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Post](
	[PostID] [bigint] NOT NULL,
	[PostName] [nvarchar](50) NULL,
	[ForumID] [bigint] NULL,
	[FieldsXml] [xml] NULL,
 CONSTRAINT [PK_Post] PRIMARY KEY CLUSTERED 
(
	[PostID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[Segments]    Script Date: 2/6/2014 2:54:05 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Segments](
	[SegmentId] [bigint] IDENTITY(1,1) NOT NULL,
	[FileId] [bigint] NULL,
	[OrderId] [int] NOT NULL,
	[Bytes] [varbinary](max) NULL,
	[StorageType] [nchar](10) NULL,
	[FullName] [nvarchar](2000) NULL,
	[Name] [nvarchar](500) NULL,
	[Updated] [datetime] NULL,
	[Created] [datetime] NULL,
	[Html] [nvarchar](max) NULL,
	[AppUser] [nvarchar](50) NULL,
 CONSTRAINT [PK_Segments] PRIMARY KEY CLUSTERED 
(
	[SegmentId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[WebFile]    Script Date: 2/6/2014 2:54:05 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[WebFile](
	[FileId] [bigint] IDENTITY(1,1) NOT NULL,
	[FolderId] [bigint] NULL,
	[StorageType] [nchar](10) NULL,
	[FullName] [nvarchar](2000) NULL,
	[Name] [nvarchar](500) NULL,
	[Size] [bigint] NULL,
	[Updated] [datetime] NULL,
	[Created] [datetime] NULL,
	[Html] [nvarchar](max) NULL,
	[AppUser] [nvarchar](50) NULL,
 CONSTRAINT [PK_WebFile] PRIMARY KEY CLUSTERED 
(
	[FileId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[WebFolder]    Script Date: 2/6/2014 2:54:05 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[WebFolder](
	[FolderId] [bigint] IDENTITY(1,1) NOT NULL,
	[ParentId] [bigint] NULL,
	[StorageType] [nchar](10) NULL,
	[FullName] [nvarchar](2000) NULL,
	[Name] [nvarchar](500) NULL,
	[Updated] [datetime] NULL,
	[Created] [datetime] NULL,
	[Html] [nvarchar](max) NULL,
	[AppUser] [nvarchar](50) NULL,
 CONSTRAINT [PK_WebFolder] PRIMARY KEY CLUSTERED 
(
	[FolderId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
ALTER TABLE [dbo].[AppUser] ADD  CONSTRAINT [DF_AppUser_GlobalID]  DEFAULT (newid()) FOR [GlobalID]
GO
ALTER TABLE [dbo].[AppUser] ADD  CONSTRAINT [DF_AppUser_InWorkflow]  DEFAULT ('new') FOR [InWorkflow]
GO
ALTER TABLE [dbo].[Segments] ADD  CONSTRAINT [DF_Segments_Updated]  DEFAULT (getdate()) FOR [Updated]
GO
ALTER TABLE [dbo].[Segments] ADD  CONSTRAINT [DF_Segments_Created]  DEFAULT (getdate()) FOR [Created]
GO
ALTER TABLE [dbo].[WebFile] ADD  CONSTRAINT [DF_WebFile_Updated]  DEFAULT (getdate()) FOR [Updated]
GO
ALTER TABLE [dbo].[WebFile] ADD  CONSTRAINT [DF_WebFile_Created]  DEFAULT (getdate()) FOR [Created]
GO
ALTER TABLE [dbo].[WebFolder] ADD  CONSTRAINT [DF_WebFolder_Created1]  DEFAULT (getdate()) FOR [Updated]
GO
ALTER TABLE [dbo].[WebFolder] ADD  CONSTRAINT [DF_WebFolder_Created]  DEFAULT (getdate()) FOR [Created]
GO
ALTER TABLE [dbo].[Forum]  WITH CHECK ADD  CONSTRAINT [FK_Forum_WebFile] FOREIGN KEY([FileID])
REFERENCES [dbo].[WebFile] ([FileId])
GO
ALTER TABLE [dbo].[Forum] CHECK CONSTRAINT [FK_Forum_WebFile]
GO
ALTER TABLE [dbo].[Post]  WITH CHECK ADD  CONSTRAINT [FK_Post_Forum] FOREIGN KEY([ForumID])
REFERENCES [dbo].[Forum] ([ForumID])
GO
ALTER TABLE [dbo].[Post] CHECK CONSTRAINT [FK_Post_Forum]
GO
ALTER TABLE [dbo].[Segments]  WITH CHECK ADD  CONSTRAINT [FK_Segments_WebFile] FOREIGN KEY([FileId])
REFERENCES [dbo].[WebFile] ([FileId])
GO
ALTER TABLE [dbo].[Segments] CHECK CONSTRAINT [FK_Segments_WebFile]
GO
ALTER TABLE [dbo].[WebFile]  WITH CHECK ADD  CONSTRAINT [FK_WebFile_WebFolder] FOREIGN KEY([FolderId])
REFERENCES [dbo].[WebFolder] ([FolderId])
GO
ALTER TABLE [dbo].[WebFile] CHECK CONSTRAINT [FK_WebFile_WebFolder]
GO
ALTER TABLE [dbo].[WebFolder]  WITH CHECK ADD  CONSTRAINT [FK_WebFolder_WebFolder] FOREIGN KEY([ParentId])
REFERENCES [dbo].[WebFolder] ([FolderId])
GO
ALTER TABLE [dbo].[WebFolder] CHECK CONSTRAINT [FK_WebFolder_WebFolder]
GO

